package com.sunxueqi.project.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sunxueqi.framework.annotation.VLog;
import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.system.service.IFileService;
import com.sunxueqi.project.system.vo.LocalFile;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags="文件管理")
@RestController
@RequestMapping("/system/file")
public class FileController extends BaseController{

	@Autowired
	private IFileService fileService;
	
	/**
	 * 上传文件
	 * @param fileName
	 * @param multipartFile
	 * @return
	 */
	@ApiOperation("上传文件")
	@PostMapping
	public ResponseData uploadFile(@RequestParam MultipartFile file) {
		int a = fileService.uploadFile(file);
		System.out.println(a);
		return super.getResponseDataRow(a);
	}
	
	/**
	 * 
	 * @param localFile
	 * @return
	 */
	@VLog(title = "服务器文件查询")
	// @PreAuthorize("@permissionService.hasPermission('system:localfile:list')")
	@GetMapping("/list")
	public ResponseData list(LocalFile localFile) {
		startPage();
		List<LocalFile> list = fileService.selectLocalFileList(localFile);
		return ResponseData.successTableData(list);
	}
	
}
